<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/12/26
 * Time: 13:23
 */
namespace app\admin\controller;
use app\common\lib\db\DbCommon;
use app\common\lib\exception\ApiException;
use think\Db;
use think\Request;

/**
 * Class Rely 意见反馈
 * @package app\admin\controller
 */
class Rely extends Base{
    public function index(){
        if (request()->isAjax()) {
            extract(input()); //将接收的参数赋值给变量
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $map =array();
            if(isset($keyword)&&$keyword!="")
            {
                $map['opinion_name'] = ['like',"%" . $keyword . "%"];
            }
            try{
                $count = Db::name('opinion')->where($map)->count();  //总条目数据
                $lists = Db::name('opinion')->where($map)->page($NowPage,$limits)->select();  //当前页
            }catch (\Exception $e) {
                return json(['code' => 500, 'msg' => $e->getMessage()]);
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    public function update()
    {
        $opinion_id = Request::instance()->param('user_id');
        $data = Model('Opinion')->get(['opinion_id'=>$opinion_id]);
        $this->assign(['data' => $data]);
        return $this->fetch();
    }

    /**
     * Ajax抛送删除
     * @return \think\response\Json
     */
    public function del()
    {
        $opinion_id = Request::instance()->param('id');
        $res = Model('Opinion')->where(['opinion_id'=>$opinion_id])->delete();
        if(!$res) {
            return json(['code'=>500,'msg'=>'数据库错误']);
        }
        return json(['code'=>200,'msg'=>'已删除']);
    }
}